package com.pkche.core.advanced.util;

import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

/**
 * 读取properties静态资源配置
 * @author zhongpengzhan
 *
 */
public class WJUtils {
	public final static Logger log = Logger.getLogger(WJUtils.class);
	public static String SMSUrl = null;
	public static String SMSId = null;
	public static String SMSPwd = null;
	/**
	 * 阿里云OSSURL公网前缀
	 */
	public static String aliossURL =  null;
	
	/**
	 * 主域名
	 */
	public static String mainDomain = null;
	
	/**
	 * 图片在oss上的目录位置
	 */
	public static String aliossURI_IMG = null;
	
	/**
	 * 音频文件在oss上的目录位置
	 */
	public static String aliossURI_AUDIO = null;
	
	/**
	 * 视频文件在oss上的目录位置
	 */
	public static String aliossURI_VIDEO = null;
	
	/**
	 * 地理位置接口-Google
	 */
	public static String addressServiceUrlGoogle;
	
	/**
	 * 地理位置接口-Baidu
	 */
	public static String addressServiceUrlBaidu;

	
	static {
		/*InputStream inStream = WJUtils.class.getClassLoader().
				getResourceAsStream("/META-INF/application.properties");*/
		org.springframework.core.io.Resource resource = new ClassPathResource("/META-INF/application.properties");
		Properties prop = null;
		try {
			prop = PropertiesLoaderUtils.loadProperties(resource);
			SMSUrl = prop.getProperty("SMSUrl");
			SMSId = prop.getProperty("SMSId");
			SMSPwd = prop.getProperty("SMSPwd");
			aliossURL = prop.getProperty("aliossURL");
			mainDomain = prop.getProperty("mainDomain");
			aliossURI_IMG = prop.getProperty("aliossURI_IMG");
			aliossURI_AUDIO = prop.getProperty("aliossURI_AUDIO");
			aliossURI_VIDEO = prop.getProperty("aliossURI_VIDEO");
			addressServiceUrlGoogle = prop.getProperty("addressServiceUrlGoogle");
			addressServiceUrlBaidu = prop.getProperty("addressServiceUrlBaidu");
		} catch (IOException e) {
			e.printStackTrace();
			log.error("读取application资源文件异常.", e);
		}
	}
	
	/**
	 * 微信配置appid
	 */
	public static String token = "WJTOKENQAZQWERASD";  
	/**
	 * 微信appid
	 */
 	public static String appid = null;
	/**
	 * 微信secret
	 */
 	public static String secret = null;
 	/**
 	 * 临时文件存储目录
 	 */
    public static String tempDir = null;
	/**
 	 * 微信远程下载文件的URL
 	 */
    public static String weChatFilerRmoteURL = null;
    /**
 	 * 微信接口获取用户信息的URL
 	 */
	public static String weChatUserInfoURL = null;
	  /**
	 	 * 微信接口获取Access_Token的URL
	 	 */
	public static String accessTokenUrl = null;
	  /**
	 	 * 微信接口二维码调度接口
	 	 */
	public static String qrCodeUrl = null;
	public static String downLoadQrCode = null;
	
	/**
	 * 微信素材上传地址
	 */
	public static String uploadChatFileURL = null;
	
	/**
	 * 获取JS API Tiket的get请求地址
	 */
	public static String jsAPITicket = null;
	
	/**
	 * 微信静默认证地址
	 */
	public static String wxloginTokenUrl = null;
	
	/**
	 * 客服消息接口地址
	 */
	public static String wxCustomerMsgUrl = null;
	
	/**
	 * 获取到用户openid时，根据openid去取得用户信息的url
	 */
	public static String wxWebGetUserInfoUrl = null;
	
	/**
	 * 根据URL方式获取用户openid的URL
	 */
	public static String wxOpenGetOpenIdUrl = null;
	
	/**
	 * 微信支付所需的商户号
	 */
	public static String merchantId = null;
	
	/**
	 * 商户支付密钥
	 */
	public static String wxPaySecret = null;
	
	/**
	 * 微信支付方式，默认是jsapi方式
	 */
	public static String wxPayTradeType = null;
	
	/**
	 * 微信支付--统一下单接口URL
	 */
	public static String wxPayUrl = null;
	
	/**
	 * 微信支付--关闭订单接口URL
	 */
	public static String wxPay_closeOrderUrl = null;
	
	/**
	 * 微信支付--查询订单接口URL
	 */
	public static String wxPay_queryOrderUrl = null;
	
	/**
	 * 微信支付--退款接口URL
	 */
	public static String wxPay_refundUrl = null;
	
	static {
		org.springframework.core.io.Resource r = new ClassPathResource("/META-INF/weixin.properties");
		Properties props = null;
		try {
			props = PropertiesLoaderUtils.loadProperties(r);
			token = props.getProperty("weixin.token");
			appid = props.getProperty("appid");
			secret = props.getProperty("appsecret");
			tempDir = props.getProperty("weChatTempDir");
			weChatFilerRmoteURL = props.getProperty("weChatFilerRmoteURL");
			weChatUserInfoURL = props.getProperty("weChatUserInfoURL");
			accessTokenUrl = props.getProperty("accessTokenUrl");
			qrCodeUrl = props.getProperty("qrCodeUrl");
			downLoadQrCode = props.getProperty("downLoadQrCode");
			uploadChatFileURL = props.getProperty("uploadChatFileURL");
			jsAPITicket = props.getProperty("jsAPITicket");
			wxloginTokenUrl = props.getProperty("wxloginTokenUrl");
			wxCustomerMsgUrl = props.getProperty("wxCustomerMsgUrl");
			wxWebGetUserInfoUrl  =props.getProperty("wxWebGetUserInfoUrl");
			wxOpenGetOpenIdUrl = props.getProperty("wxOpenGetOpenIdUrl");
			merchantId = props.getProperty("merchantId");
			wxPaySecret = props.getProperty("wxPaySecret");
			wxPayTradeType = props.getProperty("wxPayTradeType");
			wxPayUrl = props.getProperty("wxPayUrl");
			wxPay_closeOrderUrl = props.getProperty("wxPay_closeOrderUrl");
			wxPay_queryOrderUrl = props.getProperty("wxPay_queryOrderUrl");
			wxPay_refundUrl = props.getProperty("wxPay_refundUrl");
		} catch (IOException e) {
			log.error("微信配置读取异常.",e);
		}
	}
	
}
